home *** CD-ROM | disk | FTP | other *** search
- Path: news.seanet.com!usenet
- From: mitchell@seanet.com (where am i?)
- Newsgroups: comp.lang.c
- Subject: my atoi function, could someone suggest...
- Date: Wed, 03 Jan 1996 12:18:50 GMT
- Organization: Seanet Online Services, Seattle WA
- Message-ID: <4cf7ap$q4u@kaleka.seanet.com>
- NNTP-Posting-Host: mitchell.seanet.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hello. This is my first attempt at an atoi function. Although it
- works and behaves just like atoi, I was wondering if anyone would care
- for a look and make suggestions back to me about its efficiency.
-
- int atoi ( char *change )
- {
- int newint = 0, sign = 1;
-
- while ( *change )
- {
- if ( (*change < '0' || *change > '9') && *change != '-' )
- {
- *change++;
- }
- else
- {
- if ( *change == '-' )
- {
- *change++;
- if ( *change >= '0' && *change <= '9' )
- sign = -1;
- }
- if ( *change >= '0' && *change <= '9' )
- {
- while ( sign )
- {
- newint *= 10;
- newint = newint + *change - 48;
- *change++;
- if ( *change < '0' || *change > '9' )
- {
- return ( newint * sign );
- exit (0);
- }
- }
- }
- }
- }
- return ( 0 );
- }
-
- Thank you all very much.
-
- Mitch
-
-